#pragma once


/**
 * \file
 * \ingroup Core
 * implementation file: File:PDE.cpp
 * ---
 *	Defines class PDE (Partial Differential Equation)
 *
*/

/**
 * \ingroup Core
 * \brief Encapsulates all the data of a partial differential equation as an immutable object
 * \author HapTork
*/
class PDE
{
private:

protected:
	long t;
	double** d;
	//static const short BOTTOM;
	//static const short LEFT;
	//static const short TOP;
	//static const short RIGHT;

public:
	bool isExact;
	char bound[2][4][128];		//stores expressions for boundary values.
	char initial[2][128];			//stores expressions for initial solution.
	char exact[2][128];		//stores expresstions for exact solution
	char aux[128];		//stores expressions for auxiallary function.
	
	/** 2-d partial differential equation Constructor: Definition
	 * ---
	 * Constructs a pde instance with given computational domain and expressions.
	 * @param x1 lower boundary of x-axis domain
	 * @param x2 upper boundary of x-axis domain
	 * @param y1 lower boundary of y-axis domain
	 * @param y2 upper boundary of y-axis domain
	 * @param b's	 boundaries for u and v. if its one variable then b10-b13 will are by default NULL.
	 * @param a		auxillary function expression, a grid cooked with this will be a parameter to any scheme together with
					cooked numerical solution grid. Can be used as f(x) in poisson's equation or scheme may have its own instructions for this.
	 * @param e\ev	exact value expression for u\v
	 * @param i\iv	initial value expression for u\v
	 */

	PDE(double x1,double x2, double y1, double y2,long t,char* b00,char*b01,char*b02,char*b03,char* a, char* e,char* i,
		char* b10=NULL,char*b11=NULL,char*b12=NULL,char*b13=NULL,char* ev=NULL,char*iv=NULL){
		d=new double*[2];
		d[0]=new double[2];
		d[1]=new double[2];
		d[0][0]=x1;
		d[0][1]=x2;
		d[1][0]=y1;
		d[1][1]=y2;
		this->t=t;
		if(e==NULL || e[0]==NULL || e[0]=='0')	isExact=false; else isExact=true;
		if(isExact)	strcpy_s(exact[0],e);
		if(isExact && ev!=NULL)	strcpy_s(exact[1],ev);
		if(b00)strcpy_s(bound[0][0],b00);
		if(b01)strcpy_s(bound[0][1],b01);
		if(b02)strcpy_s(bound[0][2],b02);
		if(b03)strcpy_s(bound[0][3],b03);
		if(b10)strcpy_s(bound[1][0],b10);
		if(b11)strcpy_s(bound[1][1],b11);
		if(b12)strcpy_s(bound[1][2],b12);
		if(b13)strcpy_s(bound[1][3],b13);
		if(i)strcpy_s(initial[0],i);
		if(a)strcpy_s(aux,a);
		if(iv)strcpy_s(initial[1],iv);
	}


	
	virtual ~PDE(){
		int i=2;
		while(i--)
			delete[] d[i];
		//i=4;
		//while(i--)
			//delete[] bound[i];
		//delete initial;
		//delete aux;
	}


	/** Method : getDomain
	* ---
	* \return a double pointer to two-dimensional computational domain array d.
	*/

	double** getD(){
		return d;
	}

	/** Method : getT
	* ---
	* \return the computational final time t for a steady PDE
	*/
	long getT(){return t;}

	/** Method : getDx
	* ---
	* \param	nx	the number of mesh points along x
	* \return		the mesh step size along x-axis for the nx value
	*/
	double getDx(int nx){
		return (d[0][1]-d[0][0])/(nx-1);
	}

	/** Method : getDy
	* ---
	* \param	ny	the number of mesh points along y
	* \return		the mesh step size along y-axis for the nx value
	*/
	double getDy(int ny){
		return (d[1][1]-d[1][0])/(ny-1);
	}
	/** Method : exact
	* ---
	* stores expression for analytical solution.
	* \return returns value depending on x and y.
	*/

	//double exact(double x,double y){
	//	return 0;
	//}

	/** Method : boundary
	* ---
	* stores expression for boundary solution.
	* \return returns value depending on x and boundary y.
	*/

	//double boundary(int x, short y){
	//	return 0;
	//}

	/** Method : aux
	* ---
	* stores expression for analytical solution.
	* \return returns value depending on x and y.
	*/

	//double aux(double x,double y){
	//	return 0;
	//}
};

//const short PDE::BOTTOM=0;
//const short PDE::LEFT=1;
//const short PDE::TOP=2;
//const short PDE::RIGHT=3;


/*! \mainpage 
 *
 * \section intro_sec Introduction
 *
 * The project aims at building a software which makes organization, comparison and study of various finite difference schemes easy and effective. 
 * It also aims at being a tool to implement, test and share new schemes easily and effectively by everyone who is in the finite difference world no-matter a programmer or non-programmer.
 *  \image html scr_shot.jpg
   *  \image latex scr_shot.jpg "Screenshot of the software application" width=14cm
 * 
 * \section ftr Features
 * Easy and simplified user-interface with MFC fluent.
 * List and Graph View of solutions with automated filtered of typical mesh points for better understanding results.
 * Better Accuracy and run-time comparison of schemes with plots and charts.
 * Addition and easy integration of new schemes with .dll file loading capabilities.
 * Rich numerical library and support for building, testing and sharing new schemes as dll files.
 * \section desgn Design
 * The modular design of the program is derived from the natural approach for solving partial differential equations.
 * The core classes are totally independent of user-interface that is implemented using MFC(Microsoft Foundatoin Classes).
 * The interaction among various core class modules is shown below:
 *  
   *  \image html cls_diag.jpg
   *  \image latex cls_diag.jpg "class diagrams with inter-relationship" width=14cm
 * The PDE class encapsulates all the values of a partial differential equations. With the help of a PDE class and discretization values, a numerical solution grid is formed. The work of solving this numerical grid is then delegated to a scheme module.
 * The Poission_scm is an example of a scheme module, the program can load a valid scheme module as .dll file. The program then delegate the solving of cfdGrid to any of the scheme modules chosen. This is used by a user-interface to show results.
 * \section  rcs Resources
 * The code is written with Visual Studio 2010. With c++ language, MFC framework, uses MathGL library for graphing. Doxygen is used for documenting and git is used for version control. Corel-Draw and Photoshop for icons and graphics.
 */


